package com.cn.crmsystem.controller.customerController;

import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.pojo.User;
import com.cn.crmsystem.pojo.Care;
import com.cn.crmsystem.service.customerService.CareService;
import io.swagger.annotations.*;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@Api(value ="关怀数据test",tags ="关怀数据接口API")
public class CareController {

    @Autowired
    private CareService careService;

    //获取当前登录的用户pojo对象
    //User user = (User) SecurityUtils.getSubject().getPrincipal();
    @ResponseBody
    @RequestMapping(value = "/insertCare",method = RequestMethod.POST)
    @ApiOperation(value ="新增关怀数据接口",notes = "填写关怀基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "Care",value = "关怀基本信息",required = false)
    public ResultJson insertCare(@RequestBody Care care){
         Login login = (Login) SecurityUtils.getSubject().getPrincipal();
//        Login login =new Login();
//        login.setUser_id(1);
        System.out.println(login.getUser_id());
        return careService.insertCare(care,login);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteCare",method = RequestMethod.POST)
    @ApiOperation(value ="删除关怀数据接口",notes = "传入要删除的数据id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "关怀数据id",required = false,dataType = "Integer",paramType = "query")
    public ResultJson deleteCare(Integer id){
        System.out.println(id);
        return careService.deleteCare(id);
    }

    @ResponseBody
    @RequestMapping(value = "/updateCare",method = RequestMethod.POST)
    @ApiOperation(value ="修改关怀数据接口",notes = "填写修改后关怀基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "care",value = "修改后关怀基本信息",required = false)
    public ResultJson updateCare(@RequestBody Care care) {
        //User user = (User) SecurityUtils.getSubject().getPrincipal();
        System.out.println(care);
        return careService.updateCare(care);
    }

    @ResponseBody
    @RequestMapping(value = "/updateCareUser",method = RequestMethod.POST)
    @ApiOperation(value ="修改关怀负责人数据接口",notes = "传入修改后的负责人id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "修改后的负责人id",required = false,dataType = "Integer",paramType = "query")
    public ResultJson updateCareUser(@RequestParam Integer id) {
        return careService.updateCareUser(id);
    }

    @ResponseBody
    @RequestMapping(value = "/selectCare",method = RequestMethod.POST)
    @ApiOperation(value ="条件查询关怀数据接口",notes = "填写筛选条件数据",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customer_name",value = "关怀客户名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "contacts_name",value = "关怀联系人名字",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "programme_time",value = "关怀时间",paramType = "query",dataType = "Date",required = false),
            @ApiImplicitParam(name = "user_name",value = "负责人id",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "create_name",value = "创建人id",paramType = "query",dataType = "String",required = false)
    })
    public ResultJson<List> selectCare(@RequestBody @RequestParam @ApiParam(required = false) Map<String,Object> map) {
        System.out.println(map.get("customer_name"));
        return careService.selectCare(map);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteAllCare",method = RequestMethod.POST)
    @ApiOperation(value ="批量删除关怀数据接口",notes = "传入要删除的数据id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "ids",value = "关怀id",paramType = "query",dataType = "Integer",required = false)
    public ResultJson deleteAllCare(Integer[] ids){
        System.out.println(ids.length);
        return careService.deleteAllCare(ids);

    }
}
